// 获取应用实例
const app = getApp()
Page({
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    menuHeight: app.globalData.navBarHeight,
     userID: '',
  },
  goSetup() {
    wx.navigateTo({
      url: `/pages/setup/setup`
    });
  },
  goLike() {
    wx.navigateTo({
      url: `/pages/like/like`
    });
  },
  goClass() {
    wx.navigateTo({
      url: `/pages/myclass/myclass`
    });
  },
  goKefu() {
    wx.navigateTo({
      url: `/pages/kefu/kefu`

    });
  },
  goAboutus() {
    wx.navigateTo({
      url: `/pages/aboutUs/aboutUs`
    });
  },
  
  // 事件处理函数
  bindViewTap() {
    wx.showModal({
      title: '系统提示',
      content: '更改头像信息？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  onLoad() {
   
  },
 
  onShow(){
    let token = wx.getStorageSync("token") ? JSON.parse(wx.getStorageSync("token")) : ''
    if(!token){
      wx.showModal({
				title: '提示',
				content: '请先登录',
				success(res) {
					if (res.confirm) {
						wx.getUserProfile({
							desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
							success: (res) => {
								console.log('--------------------', res)
								wx.navigateTo({
                  url: '/pages/login/login',
                })
							}
						})

					} else if (res.cancel) {
            console.log('用户取消了登录')
            wx.switchTab({
              url: '/pages/index/index',
            })
					}
				}
			})
    }
    this.setData({
      userID:token.uid
    })
  },
  getUserProfile(e) {
    wx.getUserProfile({
      desc: '展示用户信息',
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  },
})